package Ui;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

import Messaging.Notification;
import Messaging.NotificationManager;

/*
 * @author Roch San Buenaventura
 */

public class MainMenu extends JPanel 
{
	
	private JButton newGame_, quitGame_, continue_, support_;
	Display display_;
	private GameOptions options_;
	
	static final long serialVersionUID = 2;
	
	public MainMenu(Display d) {
		display_ = d;
		int frameWidth = 600, frameHeight = 400;
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

		Point location = new Point((int) (screen.getWidth() - frameWidth) / 2,
				(int) (screen.getHeight() - frameHeight) / 2);

		this.setSize(frameWidth, frameHeight);
		this.setLayout(null);
		
		JLabel titleBar = new JLabel();
		ImageIcon title = new ImageIcon("MonopolyImages/Logos/MonopolyLogo.jpg");
		titleBar.setIcon(title);
        titleBar.setOpaque(true);
        titleBar.setBounds(0, 0, 600, 400);
		this.add(titleBar);

		newGame_ = new JButton("New Game");
		newGame_.setBounds(245, 290, 95, 20);
		newGame_.setMnemonic(KeyEvent.VK_N);
		newGame_.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                if (options_ == null)
                	options_ = new GameOptions(MainMenu.this);
                else {
                	options_.showFirstPagePanels();
                	options_.setVisible(true);
                }
                hideMenu();
            }

        });
		
		quitGame_ = new JButton("Quit Game");
		quitGame_.setBounds(350, 320, 95, 20);
		quitGame_.setMnemonic(KeyEvent.VK_Q);
		quitGame_.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                System.exit(0);
            }
        });

        continue_ = new JButton("Continue");
        continue_.setBounds(140, 320, 95, 20);
        continue_.setMnemonic(KeyEvent.VK_C);
        
        support_ = new JButton("Support");
        support_.setBounds(245, 320, 95, 20);
        support_.setMnemonic(KeyEvent.VK_S);
				
		add(titleBar);
		titleBar.add(newGame_);
		titleBar.add(quitGame_);
		titleBar.add(continue_);
		titleBar.add(support_);
		
		DisplayAssembler display = DisplayAssembler.getInstance();
		display.addComponent(this, location, JLayeredPane.PALETTE_LAYER);
		setVisible(true);

		NotificationManager.getInstance().addObserver(Notification.START_GAME,
				this, "hideMenu");
	}
	
	public void hidePanels() {
		newGame_.setVisible(false);
        quitGame_.setVisible(false);
        continue_.setVisible(false);
        support_.setVisible(false);
	}
	
	public void hideMenu() {
		setVisible(false);
	}
	
	public void showMenu() {
		setVisible(true);
	}
	
	public static void main(String[] args) {
		Display display = new Display();
		new MainMenu(display);

	}
}